﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    enum Attack
    {
        剪刀 = 1,
        石头,
        布
    }
    class Program
    {
        static int winTime = 0;
        static int loseTime = 0;
        //猜拳
        static void Main(string[] args)
        {
            Master master = new Master();
            master.Judgment = "裁判";

            master.JudgmentSayBegin();

            Console.WriteLine("请选择对手角色：1、刘备2、孙权3、曹操");
            int keyNpcName = int.Parse(Console.ReadLine());
            bool flagNpcName = true;

            while (flagNpcName)
            {
                switch (keyNpcName)
                {
                    case 1:
                        master.NpcName = "刘备";
                        flagNpcName = false;
                        break;
                    case 2:
                        master.NpcName = "孙权";
                        flagNpcName = false;
                        break;
                    case 3:
                        master.NpcName = "曹操";
                        flagNpcName = false;
                        break;
                    default:
                        Console.WriteLine("输入错误");
                        break;
                }
            }

            Console.WriteLine("请输入您的昵称");
            string playerName = Console.ReadLine();
            master.PlayerName = playerName;
            Console.WriteLine(master.PlayerName);
            
            

            Console.WriteLine(master.PlayerName + " VS " + master.NpcName);

            bool b1 = true;

            while (b1)
            {
                Console.WriteLine("开始游戏吗？y/n");
                string gameBegin = Console.ReadLine();


                if (gameBegin == "y"||gameBegin == "n")
                {

                            
                    switch (gameBegin)
                    {
                        case "y":
                            Random ran = new Random();
                            int npcAttack = ran.Next(1, 4);

                            Console.WriteLine("请出拳：1、剪刀 2、石头 3、布");
                            int playerAttack = int.Parse(Console.ReadLine());

                            switch (playerAttack)
                            {
                                case 1:
                                    PlayerAttackIsScissor(npcAttack);
                                    break;
                                case 2:
                                    PlayerAttackIsStone(npcAttack);
                                    break;
                                case 3:
                                    PlayerAttackIsCloth(npcAttack);
                                    break;
                                default:
                                    break;
                            }
                            break;
                        case "n":
                            EndGame(winTime,loseTime);
                            b1 = false;
                            break;
                        default:
                            Console.WriteLine("输入错误");
                            break;
                    }
                }
            }
        }

        private static void PlayerAttackIsCloth(int npcAttack)
        {
            Master master = new Master();

            switch (npcAttack)
            {
                case 1:
                    Console.WriteLine(master.PlayerName + "出了：布");
                    Console.WriteLine(master.NpcName + "出了：剪刀");
                    Console.WriteLine("输了");
                    loseTime += 1;
                    break;
                case 2:
                    Console.WriteLine(master.PlayerName + "出了：布");
                    Console.WriteLine(master.NpcName + "出了：石头");
                    Console.WriteLine("赢了");
                    winTime += 1; 
                    break;
                case 3:
                    Console.WriteLine(master.PlayerName + "出了：布");
                    Console.WriteLine(master.NpcName + "出了：布");
                    Console.WriteLine("平局");
                    break;
                default:
                    break;
            }
        }

        private static void PlayerAttackIsStone(int npcAttack)
        {
            Master master = new Master();

            switch (npcAttack)
            {
                case 1:
                    Console.WriteLine(master.PlayerName+"出了：石头");
                    Console.WriteLine(master.NpcName+"出了：剪刀");
                    Console.WriteLine("赢了");
                    winTime += 1;
                    break;
                case 2:
                    Console.WriteLine(master.PlayerName + "出了：石头");
                    Console.WriteLine(master.NpcName + "出了：石头");
                    Console.WriteLine("平局");
                    break;
                case 3:
                    Console.WriteLine(master.PlayerName + "出了：石头");
                    Console.WriteLine(master.NpcName + "出了：布");
                    Console.WriteLine("输了");
                    loseTime += 1;
                    break;
                default:
                    break;
            }
        }

        private static void PlayerAttackIsScissor(int npcAttack)
        {
            Master master = new Master();

            switch (npcAttack)
            {
                case 1:
                    Console.WriteLine(master.PlayerName + "出了：剪刀");
                    Console.WriteLine(master.NpcName + "出了：剪刀");
                    Console.WriteLine("平局");
                    break;
                case 2:
                    Console.WriteLine(master.PlayerName + "出了：剪刀");
                    Console.WriteLine(master.NpcName + "出了：石头");
                    Console.WriteLine("输了");
                    loseTime += 1;
                    break;
                case 3:
                    Console.WriteLine(master.PlayerName + "出了：剪刀");
                    Console.WriteLine(master.NpcName + "出了：布");
                    Console.WriteLine("赢了");
                    winTime += 1;
                    break;
                default:
                    break;
            }
        }

        private static void EndGame(int winTime,int loseTime)
        {
            Console.WriteLine("宁赢了："+winTime);
            Console.WriteLine("宁输了："+loseTime);

            Console.WriteLine("程序已退出");
        }
    }
}
